package com.lucenly.spell.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lucenly.spell.R
import com.next.easynavigation.view.EasyNavigationBar
import com.youth.banner.adapter.BannerAdapter

class TypeTabAdapter : RecyclerView.Adapter<TypeTabAdapter.ItemHolder>{
    var position = 0
    var context: Context? = null
    var data:List<String> = arrayListOf()
    constructor(data: List<String>, context: Context){
        this.data = data
        this.context = context
    }


    class ItemHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tvTab: TextView = itemView.findViewById(R.id.tvTab)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_tab, parent, false)
        return ItemHolder(view)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.tvTab.text = data[position]
        if (this.position == position){
            holder.tvTab.setTextSize(EasyNavigationBar.TextSizeType.TYPE_SP,18f)
            holder.tvTab.setTextColor(Color.parseColor("#ffffff"))
            holder.tvTab.setBackgroundResource(R.drawable.tab_shape)
        }else{
            holder.tvTab.setTextSize(EasyNavigationBar.TextSizeType.TYPE_SP,14f)
            holder.tvTab.setTextColor(Color.parseColor("#323232"))
            holder.tvTab.setBackgroundColor(Color.parseColor("#00000000"))
        }
        holder.tvTab.setOnClickListener {
            this.position = position
            notifyDataSetChanged()
        }
    }
}